/* The main file of heightmapRT.
 * Most of the logic takes place elsewhere.
 */
#include <iostream>
#include <time.h>
#include "FreeImage/FreeImage.h"

#include "User.h"
#include "Bitmap3f.h"
#include "Heightmap.h"
#include "util_gl.h"
#include "monoSample.h"

using namespace std;

User user;
FIBITMAP* testBitmapRaw;
Bitmap3f testBitmap;
Heightmap heightmap;

void render() {
    user.render();
}

void reshape(int w, int h) {
    user.reshape(w, h);
}

void idle() {
    user.idle();
}

void processNormalKeys(unsigned char key, int x, int y) {
    user.processNormalKeys(key, x, y);
}

void keyboardUp(unsigned char key, int x, int y) {
    user.keyboardUp(key, x, y);
}

void mouseState(int button, int state, int x, int y) {
    user.mouseState(button, state, x, y);
}

void mouseMotion(int x, int y) {
    user.mouseMotion(x, y);
}

int main(int argc, char* argv[]) {
    FreeImage_Initialise();
    
    if (argc > 1) user.useConfigFile(argv[1]);
    else user.useConfigFile("config.txt");

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

    glutInitWindowPosition(100,100);
    glutInitWindowSize(user.viewer.viewsizeX, user.viewer.viewsizeY);
    glutCreateWindow("heightmapRT");

    user.ready();

    glutIgnoreKeyRepeat(GLUT_KEY_REPEAT_OFF); 
    glutDisplayFunc(render);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);	
    glutKeyboardFunc(processNormalKeys);
    glutKeyboardUpFunc(keyboardUp);
    glutMouseFunc(mouseState);
    glutMotionFunc(mouseMotion);
    
    glutMainLoop();
    return 0;
}